--沉默为剑
local chenmoweijian = fk.CreateSkill {
    name = "mcdh_chenmoweijian",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

chenmoweijian:addEffect(fk.DamageCaused,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and player == target and data.to ~= player
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local choices = {"chenmoweijian1:"..data.to.id,"chenmoweijian2:"..data.to.id, "chenmoweijian-offense"}
        if  data.to:isNude() then
            table.removeOne(choices,"chenmoweijian2:"..data.to.id )
        end
        local cardt = player:getCardIds("he")
        local card = table.filter(cardt,function(id) return not player:prohibitDiscard(Fk:getCardById(id)) and Fk:getCardById(id).type ~= Card.TypeBasic  end)
        if #card == 0  then
            table.removeOne(choices,"chenmoweijian-offense" )
        end
        local choice = room:askForChoice(player, choices, self.name, nil, nil,{"chenmoweijian1:"..data.to.id,"chenmoweijian2:"..data.to.id, "chenmoweijian-offense"})
        if choice == "chenmoweijian1:"..data.to.id or choice == "chenmoweijian-offense" then
            room:loseHp(data.to,1,self.name)
        end
        if choice == "chenmoweijian2:"..data.to.id or choice == "chenmoweijian-offense" then
            if not data.to:isNude() then
                local id = room:askForCardChosen(player, data.to, "he", self.name)
                room:throwCard(id,self.name, data.to,player)
            end
        end
        if choice == "chenmoweijian-offense" then
            room:askForDiscard(player, 1, 1, true, self.name, false, ".|.|.|.|.|^basic", "#chenmoweijian-discard")
        end
        return true
    end
})

Fk:loadTranslationTable {
    ["mcdh_chenmoweijian"] = "沉默为剑",
    [":mcdh_chenmoweijian"] = "当你对其他角色造成伤害时，可以防止此伤害并选择一项：1.令其失去1点体力；2.弃置其一张牌；背水：弃置一张非基本牌。",
    ["chenmoweijian1"] = "1.令 %src 失去1点体力",
    ["chenmoweijian2"] = "2.弃置 %src 一张牌",
    ["chenmoweijian-offense"] = "背水：弃置一张非基本牌",
    ["#chenmoweijian-discard"] = "沉默为剑:弃置一张非基本牌",
}

return chenmoweijian